const mysql = require('mysql')

// 创建数据池
const pool = mysql.createPool({
  user: 'vip8-admin',
  password: '123456',
  database: 'vip8',
  host: '192.168.64.3',
})


module.exports = (sql,params) => {
  // 在数据池中进行会话操作
  return new Promise((resolve, reject) => {
    pool.getConnection(function (err, connection) {
      connection.query(sql,params, (error, results, fields) => {

        // 结束会话
        if(error){
          reject(error)
        }else{
          resolve(results)
        }
        connection.release();
      })
    })
  })

}

